package cn.gs.web;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.gs.domain.Customer;
import cn.gs.service.SelectCustomerService;

@Component(value = "selectCustomerAction")
@Scope("prototype")
public class SelectCustomerAction extends ActionSupport implements ModelDriven<Customer> {
	private Customer customer = new Customer();
	@Resource(name = "selectCustomerService")
	private SelectCustomerService selectCustomerService;
	private List<Customer> list;
	private String pageCount;
	private String page;
	private String pCount;

	public String allsel() {
		if (page == null) {
			page = "1";
		}
		int i = Integer.valueOf(page);
		try {
			list = selectCustomerService.selectCustomer(customer.getCust_name(), customer.getCust_linkman(), i);
			List l = selectCustomerService.selectPageCount(customer.getCust_name(), customer.getCust_linkman());
			System.out.println("查询出来的条数"+l);
			pageCount = String.valueOf(l.get(0));
			int a = Integer.valueOf(pageCount);
			
			int b = 0;
			if (a % 3 == 0) {
				b = a / 3;
			} else {
				b = a / 3 + 1;
			}
			pCount = String.valueOf(b);
			ActionContext.getContext().put("pCount", pCount);
			ActionContext.getContext().put("pageCount", pageCount);
			ActionContext.getContext().put("list", list);
			return "selSuc";
		} catch (Exception e) {
			ActionContext.getContext().put("list", list);
			return "selDef";
		}

	}

	@Override
	public Customer getModel() {
		// TODO Auto-generated method stub
		return customer;
	}

	public List<Customer> getList() {
		return list;
	}

	public void setList(List<Customer> list) {
		this.list = list;
	}

	public String getPageCount() {
		return pageCount;
	}

	public void setPageCount(String pageCount) {
		this.pageCount = pageCount;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public String getpCount() {
		return pCount;
	}

	public void setpCount(String pCount) {
		this.pCount = pCount;
	}

	public SelectCustomerService getSelectCustomerService() {
		return selectCustomerService;
	}

	public void setSelectCustomerService(SelectCustomerService selectCustomerService) {
		this.selectCustomerService = selectCustomerService;
	}

}
